home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / Tool Chest / Development Tools & Languages / Dylan Related / Mindy-1.1 (sources only) / mindy-1.1 / interp / mindy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-18  |  3.0 KB  |  116 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: mindy.c,v 1.8 94/08/18 19:51:48 wlott Exp $
  27. *
  28. * This file starts everything going.
  29. *
  30. \**********************************************************************/
  31.  
  32. #include "mindy.h"
  33. #include "init.h"
  34. #include "thread.h"
  35. #include "driver.h"
  36. #include "module.h"
  37. #include "str.h"
  38. #include "bool.h"
  39. #include "list.h"
  40. #include "obj.h"
  41. #include "sym.h"
  42. #include "func.h"
  43. #include "debug.h"
  44. #include "load.h"
  45. #include "num.h"
  46. #include "error.h"
  47.  
  48. static void invoke_main(struct thread *thread, obj_t *vals)
  49. {
  50.     obj_t *fp = thread->fp;
  51.     obj_t *args_end = fp - 4;
  52.     obj_t *old_sp = pop_linkage(thread);
  53.     struct variable *var = find_variable(module_BuiltinStuff, symbol("main"),
  54.                      FALSE, FALSE);
  55.  
  56.     if (var == NULL)
  57.     lose("main undefined?");
  58.  
  59.     thread->sp = args_end;
  60.     old_sp[0] = var->value;
  61.     invoke(thread, args_end - old_sp - 1);
  62. }
  63.  
  64. static void startup(struct thread *thread, int nargs)
  65. {
  66.     obj_t *args = thread->sp - nargs;
  67.  
  68.     push_linkage(thread, args);
  69.     set_c_continuation(thread, invoke_main);
  70.     load_do_inits(thread);
  71. }
  72.  
  73. void main(int argc, char *argv[])
  74. {
  75.     struct thread *thread;
  76.     enum pause_reason reason;
  77.     struct variable *var;
  78.  
  79.     init();
  80.  
  81.     thread = thread_create(symbol("main"));
  82.     *thread->sp++ = make_raw_function("startup", 0, TRUE, obj_False, FALSE,
  83.                       obj_Nil, obj_ObjectClass,
  84.                       startup);
  85.  
  86.     while (*++argv != NULL)
  87.     if (strcmp(*argv, "-f") == 0) {
  88.         char *file = *++argv;
  89.  
  90.         if (file)
  91.         load(file);
  92.         else
  93.         error("-f must be followed by a file name to load.");
  94.     }
  95.     else
  96.         *thread->sp++ = make_string(*argv);
  97.  
  98.     finalize_modules();
  99.  
  100.     while (1) {
  101.     thread_restart(thread);
  102.  
  103.     reason = do_stuff();
  104.     if (reason != pause_NothingToRun)
  105.         invoke_debugger(reason);
  106.  
  107.     var = find_variable(module_BuiltinStuff, symbol("exit"),
  108.                 FALSE, FALSE);
  109.     if (var == NULL)
  110.         lose("main undefined?");
  111.  
  112.     thread = thread_create(symbol("exit"));
  113.     *thread->sp++ = var->value;
  114.     }
  115. }
  116.